package com.appview;

import com.dao.StudentDao;
import com.dao.TeacherDao;
import com.model.StuException;
import com.model.Student;
import com.model.Teacher;

import javax.swing.*;

/**
 * Created by guin_guo on 2015/10/30.
 */
public class DataDeal {
    public static void addStudent(Student student){

        try {
            StudentDao studentDao = StudentDao.getInstance();
            studentDao.add(student);
        } catch (StuException e) {
            JOptionPane.showMessageDialog(InfoOperation.getInfoOperation(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }



    }
    public static void addTeacher(Teacher teacher) {
        try {
            TeacherDao teacherDao = TeacherDao.getInstance();
            teacherDao.add(teacher);
        } catch (StuException e) {
            JOptionPane.showMessageDialog(InfoOperation.getInfoOperation(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public static void updateStudent(Student student) {
        try {
            StudentDao studentDao = StudentDao.getInstance();
            studentDao.update(student);
        } catch (StuException e) {
            JOptionPane.showMessageDialog(InfoOperation.getInfoOperation(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    public static void updateTeacher(Teacher teacher) {
        try {
            TeacherDao teacherDao = TeacherDao.getInstance();
            teacherDao.update(teacher);
        } catch (StuException e) {
            JOptionPane.showMessageDialog(InfoOperation.getInfoOperation(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public static void deleteStudent(String accout) {
        try {
            StudentDao studentDao = StudentDao.getInstance();
            studentDao.delete(accout);
        } catch (StuException e) {
            JOptionPane.showMessageDialog(MainView.getMainView(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public static void deleteTeacher(String accout) {
        try {
            TeacherDao teacherDao = TeacherDao.getInstance();
            teacherDao.delete(accout);
        } catch (StuException e) {
            JOptionPane.showMessageDialog(MainView.getMainView(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
